/**
 * Created by Administrator on 2016/10/16.
 */
var express = require("express");
var router = express.Router();
var _ = require("underscore");

var connection = require('../lib/utils/DbconnectUtil');

/**
 * 查询项目列表
 */
router.post('/', function (req, res, next) {
    var messageData = {
        title: req.body.title,
        userName: req.body.userName,
        contentId: req.body.contentId,
        message: req.body.message,
        contact: req.body.contact,
    };
    if (!messageData.title || !messageData.userName || !messageData.contentId || !messageData.message || !messageData.contact ) {
        res.send({code: -1, message: '发送失败,请完整填写内容'});
        return;
    }

    messageData.id = new Date().getTime() + '';

    connection().query('INSERT INTO t_message SET ?', messageData, function (err, result) {
        if (err) {
            res.send({
                code: -1,
                message: '网络错误,发送消息失败',
            });
            return;
        }
        else {
            res.send({
                code: 0,
                message: '发送消息成功',
            });
        }

    });
});


module.exports = router;